package com.activity;


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;

import com.activity.bean.AuthBean;
import com.activity.bean.UserBean;
import com.alibaba.sdk.android.oss.OSSClient;
import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;


import com.example.apple.ddhr_new.utils.CacheUtil;
import com.example.apple.ddhr_new.utils.DataCleanManager;

public class App {

    public  static final String BucketName="meilihui-sources";
    public  static final String OSSURL="https://meilihui-sources.oss-cn-shanghai.aliyuncs.com/";

    public UserBean.UserstoreinfoBean userstoreinfoBean;
    private static App instance;
    public AuthBean authBean;
    private UserBean account;

    public OSSClient oss;

    public String cid;


    public static App getInstance() {
        if (instance == null) {
            synchronized (App.class) {
                if (instance == null) {
                    instance = new App();
                }
            }
        }
        return instance;
    }

    public UserBean getAccount() {
        if(account==null)
            account = CacheUtil.getAccount(com.example.apple.ddhr_new.App.self());
        return account;
    }

    public void setAccount(UserBean account) {
        this.account = account;
        CacheUtil.setAccount(account, com.example.apple.ddhr_new.App.self());
    }

    public static String getDeviceID(Context context) {

        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);

        @SuppressLint("MissingPermission") String imei = telephonyManager.getDeviceId();

        return imei;

    }
    public static String getAppVersion(Context context) {

        PackageManager pm = context.getPackageManager();
        PackageInfo pi = null;
        String versionName =null;
        try {
            pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName=pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }


        return versionName;

    }
    /**
     * 获取手机厂商
     *
     * @return  手机厂商
     */
    public static String getDeviceBrand() {
        return android.os.Build.BRAND;
    }

    //获取缓存大小
    public static String getCacheSize(Context context){
        String str = "";
        try {
            str =  DataCleanManager.getTotalCacheSize(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str ;
    }
    //清空缓存
    public static void cleanCache(Context context){
        DataCleanManager.clearAllCache(context);
    }


}
